package com.baosight.sczx.zm.ci.service; 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.cs.Mine;
import com.baosight.sczx.zm.ci.domain.ZMCIPersonInfo; 

/**
 * 
 * <p>Title: ServiceZMCI10.java</p>
 * <p>Description: 生产运营监视——井下人员</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2016年4月8日 下午3:00:08  郭淑芳  Create
 *</pre>
 */
public class ServiceZMCI10 extends ServiceEPBase {

	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化</p>
	 * <p>return value: ServiceZMCI10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年4月8日下午2:59:54 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");// 如果不加这个，翻页的统计和显示是错误的
		inInfo=this.query(inInfo);
		return inInfo;
	}
	
	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCI10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年4月8日下午3:02:20 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
	//	String fdMineId = inInfo.getString("fdMineId").trim();
		String fdMineId = UserSession.getInSessionProperty("miningCode").toString();
		EiInfo outInfo = new EiInfo();

		// 判断所选中节点是否集团
		if (fdMineId.equals("defaultOrg")) {
		
			ZMCIPersonInfo _dom = new ZMCIPersonInfo();
			EiBlock eiBlock = inInfo.getBlock("result");
			eiBlock.setBlockMeta(_dom.eiMetadata);
			
			// 获取下属各矿信息
			List<Map> list = new ArrayList();
			Map<String, String> _argMap = new HashMap<String, String>();
			list = dao.query("ZM02.queryTreeChild", _argMap);

			// 查询各矿人员信息
			List<ZMCIPersonInfo> infoList = new ArrayList();
			for (int i = 0; i < list.size(); i++) {
				Map<String, String> _orgMap = new HashMap<String, String>();
				_orgMap.put("fdMiningId", list.get(i).get("label").toString());
				infoList = dao.query("ZMCIPersonInfo.query",_orgMap);
				eiBlock.addRows(infoList);
			}
			outInfo.addBlock(eiBlock);
		} else {
			String date = StaticTools.getDate();
			StaticTools.setQueryParameters(inInfo, "fdLocationTime", date, false);// 添加查询条件
			StaticTools.setQueryParameters(inInfo, "fdMiningId", fdMineId, true);// 添加查询条件
			outInfo = super.query(inInfo, "ZMCIPersonInfo.query", new ZMCIPersonInfo());
		}
		outInfo.addBlock(Mine.getMineBlock("cmes.ch.mine"));
		return outInfo;
	}
}
